package com.gjy.aviator.function;

import com.googlecode.aviator.runtime.function.AbstractFunction;
import com.googlecode.aviator.runtime.type.AviatorObject;
import com.googlecode.aviator.runtime.type.AviatorString;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @author gjy
 * @version 1.0
 * @since 2024-11-04 19:27:35
 */
public class NumberAddFunction extends AbstractFunction {

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
        String n1 = arg1.stringValue(env);
        String n2 = arg2.stringValue(env);

        BigDecimal b1 = new BigDecimal(n1);
        BigDecimal b2 = new BigDecimal(n2);
        BigDecimal add = b1.add(b2);

        return new AviatorString(add.toString());
    }

    @Override
    public String getName() {
        return "numberAdd";
    }
}
